package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.model.domain.SmsCouponHistory;
import com.mall.model.vo.PageResult;
import com.mall.service.marketing.mapper.SmsCouponHistoryMapper;
import com.mall.service.marketing.service.SmsCouponHistoryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService {

    @Autowired
    private SmsCouponHistoryMapper smsCouponHistoryMapper;

    //根据优惠券id，使用状态，订单编号分页获取领取记录
    public PageResult list(Long couponId, Integer useStatus, String orderSn, Integer pageSize, Integer pageNum) {
        IPage<SmsCouponHistory> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsCouponHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(couponId != null, SmsCouponHistory::getCouponId, couponId)
                .eq(useStatus != null, SmsCouponHistory::getUseStatus, useStatus)
                .like(StringUtils.isNotEmpty(orderSn), SmsCouponHistory::getOrderSn, orderSn);
        IPage<SmsCouponHistory> pageInfo = smsCouponHistoryMapper.selectPage(page, queryWrapper);
        return new PageResult(pageNum, pageSize, (int) pageInfo.getTotal(), pageInfo.getRecords());
    }
}

